package com.breeze.blockchain.bc.service;

import com.breeze.blockchain.bc.util.BlockCache;
import com.breeze.blockchain.bc.websocket.P2PClient;
import com.breeze.blockchain.bc.websocket.P2PServer;
import jakarta.annotation.Resource;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Service;

/**
 * p2p网络服务类
 *
 * @author breeze
 */
@Service
public class P2pInitRunner implements ApplicationRunner {

  @Resource BlockCache blockCache;

  @Resource P2PServer p2pServer;

  @Resource P2PClient p2pClient;

  @Override
  public void run(ApplicationArguments args) {
    p2pServer.initP2pServer(blockCache.getP2pport());
    p2pClient.connectToPeer(blockCache.getAddress());
    System.out.println("*****难度系数******" + blockCache.getDifficulty());
    System.out.println("*****端口号******" + blockCache.getP2pport());
    System.out.println("*****节点地址******" + blockCache.getAddress());
  }
}
